package exam.test7;

public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        String oldID = "aab";
        String ret = solution.breakPalindrome(oldID);
        System.out.println(ret);
    }

    public String breakPalindrome(String oldID) {
        if (!isPalindrome(oldID)) {
            return oldID;
        }

        System.out.println("palindrome: " + oldID);
        oldID = oldID.toLowerCase();
        boolean update = false;
        for (int i = 0; i < oldID.length(); i++) {
            if (oldID.charAt(i) != 'a') {
                oldID = oldID.substring(0, i) + 'a' + oldID.substring(i + 1);
                update = true;
                break;
            }
        }
        if (!update) {
            return "IMPOSSIBLE";
        }

        return breakPalindrome(oldID);
    }

    public boolean isPalindrome(String id) {
        if (id == null) {
            return false;
        }
        if (id.length() == 1) {
            return true;
        }
        for (int i = 0; i < id.length() / 2; i++) {
            if (id.charAt(i) != id.charAt(id.length() - 1 - i)) {
                return false;
            }
        }
        return true;
    }

}
